<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Question extends Model
{
    //题目类型
    const TYPE_RADIO = 1;
    const TYPE_CHECKBOX = 2;
    const TYPE_DECIDE = 3;
    const TYPE_MASTER = 4;
    //子题默认排序
    const DEFAULT_SORT = 99;
    //选项类型
    const KEY_TYPE_TEXT = 1;
    const KEY_TYPE_IMG = 2;
    //题目类型中文
    public static $mapType = [
        self::TYPE_RADIO => '单选题',
        self::TYPE_CHECKBOX => '多选题',
        self::TYPE_DECIDE => '判断题',
        self::TYPE_MASTER => '题帽题',
    ];
    //选项中文
    public static $mapKeyType = [
        self::KEY_TYPE_TEXT => '文字',
        self::KEY_TYPE_IMG => '图片'
    ];
    protected $casts = [
        'status' => 'boolean',
        'options' => 'json',
        'keys' => 'json'
    ];
    protected $fillable = [
        'type',
        'pid',
        'status',
        'content',
        'options',
        'keys',
        'analysis',
        'answer_num',
        'correct_num',
        'sort'
    ];

    public function tags()
    {
        return $this->belongsToMany(QuestionTag::class, 'question_tag_relation', 'question_id','tag_id');
    }
}
